package l.l.w.ThinkInJave.Curr;

import org.junit.Test;

import java.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by llw on 2018/4/13/0013.
 */
public class LearThreadPool {

    @Test
    public void demo1() throws InterruptedException {
        int threadPoolSize = 10;
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(threadPoolSize);
        for(int i = 0; i < threadPoolSize * 1; ++i){
            int threadNumber = i;
            fixedThreadPool.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        System.out.println("in thread: " + threadNumber);
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        TimeUnit.MINUTES.sleep(20);
    }
}
